package org.rednebula.simple.model.service;

import org.rednebula.framework.core.IEnvironment;
import org.rednebula.framework.core.model.domain.IModel;
import org.rednebula.framework.core.model.domain.RootModel;
import org.rednebula.framework.core.model.form.IForm;
import org.rednebula.framework.core.service.AbstractAssembleService;
import org.rednebula.simple.model.form.PersonForm;
import org.rednebula.simple.model.model.PersonModel;
import org.springframework.stereotype.Component;

@Component
public class PersonAssembleService extends AbstractAssembleService {
	public IModel find(IEnvironment envi, IForm form, IModel model) {
		
		return null;
	}


	public IModel create(IEnvironment envi, IForm form, IModel model) {
		RootModel root=(RootModel)model;
		PersonForm f=(PersonForm)form;
		PersonModel p=form.getTemporayData(PersonModel.class);
		f.setPk((String)p.getIdent());
		p.openListener();
		return root;
	}

	public IModel delete(IEnvironment envi, IForm form, IModel model) {
		// TODO Auto-generated method stub
		return null;
	}

	public IModel modify(IEnvironment envi, IForm form, IModel model) {
		PersonForm f=(PersonForm)form;
		RootModel root=(RootModel)model;
		PersonModel m=(PersonModel)root.getModel(f.getPk());
		m.setEducation(f.getEducation());
		m.setName(f.getName());
		m.setSex(f.getSex());
		return model;
	}
	

}
